package com.generali.test.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService(name = "FailingWebService", targetNamespace = "http://ws.test.generali.com", endpointInterface = "com.generali.test.ws.FailingWebService")
public class FailingWebServiceImpl implements FailingWebService {

    private boolean sleepCall = true;

    /**
     * @see com.generali.test.ws.FailingWebServiceOld#calculate(java.lang.Long, java.lang.Long)
     */
    @WebMethod
    public long calculateWithTimeout(Long number1, Long number2) {
        if (this.sleepCall) {
            long sleepTime = 5000L;
            System.out.println("Sleeping " + sleepTime + " milliseconds before calculating");
            try {
                Thread.sleep(sleepTime);
            } catch (InterruptedException e) {
                System.err.println("Sleep has been interrupted");
            }
            System.out.println("End sleeping");
            this.sleepCall = false;
        } else {
            System.out.println("No sleep");
            this.sleepCall = true;
        }
        return calculate(number1, number2);
    }

    /**
     * @see com.generali.test.ws.FailingWebServiceOld#calculate(java.lang.Long, java.lang.Long)
     */
    @WebMethod
    public long calculate(Long number1, Long number2) {
        long result = number1 + number2;
        System.out.println("Result is: " + result);
        return result;
    }
}
